<template>
  <div class="common-layout">
    <el-container>
      <el-aside width="200px">
        <el-menu
            style="height: 100%;"
            active-text-color="#ffd04b"
            background-color="#545c64"
            class="el-menu-vertical-demo"
            :default-active="asideIndex"
            text-color="#fff"
            @select="handleSelect"
        >
          <el-menu-item index="4">
            <el-icon>
              <setting/>
            </el-icon>
            <span>首页</span>
          </el-menu-item>

          <el-sub-menu index="1">
            <template #title>
              <el-icon>
                <location/>
              </el-icon>
              <span>基本管理</span>
            </template>
            <el-menu-item-group>
              <el-menu-item index="1-1">用户管理</el-menu-item>
              <el-menu-item index="1-2">动态管理</el-menu-item>
              <el-menu-item index="1-3">权限管理</el-menu-item>
            </el-menu-item-group>
          </el-sub-menu>
          <el-menu-item index="2">
            <el-icon>
              <setting/>
            </el-icon>
            <span>用户信息管理</span>
          </el-menu-item>

          <el-menu-item index="3">
            <el-icon>
              <setting/>
            </el-icon>
            <span>用户动态管理</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </div>
</template>

<script lang="ts" setup>

import {clear} from "../../../utils/constant";
import {useRouter} from "vue-router";
import {onBeforeMount, onBeforeUnmount, onMounted, onUnmounted, ref} from "vue";
const router = useRouter();

//使用会话存储 当前位置
const asideIndex = ref('1-1')

onMounted(()=>{

  if(router.currentRoute.value.name === 'userManage'){
    asideIndex.value = '1-1'
  }

  if(router.currentRoute.value.name === 'index'){
    asideIndex.value = '4'
  }

})

const handleSelect = (key: string, keyPath: string[]) => {

  asideIndex.value = key
  if(key === '1-1'){
    router.push({
      name:'userManage'
    })
  }

  if(key === '4'){
    router.push({
      name:'index'
    })
  }

}

</script>

<style scoped>

.common-layout {
  display: flex;
  height: 100%;
}

</style>
